﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Data.Common;
using System.Configuration;

namespace Espam.Idiomas.Decimo.Tesis.Datos
{
    public  class BaseDatos
    {
        public SqlConnection conexion = null;



        private string cadenaConexion = "Server=192.168.100.2;Database=EspamIdiomas;User Id=Idiomas;Password=idioma$";
      

        public BaseDatos()
        {
            conexion = new SqlConnection(cadenaConexion);
            //configurar();
        }

        public void Conectar()
        {
            if (this.conexion != null && !this.conexion.State.Equals(ConnectionState.Closed))
            {
                throw new Exception("La conexion se encuentra abierta");              
            }
            try
            {
                if (this.conexion.State.Equals(ConnectionState.Closed))
                {
                    this.conexion.Open();                    
                }
            }
            catch (DataException ex)
            {

                throw new Exception("Error al conectarse a la base de datos.",ex);
            }
        }
        public void CerrarConexion()
        {
            if (this.conexion.State.Equals(ConnectionState.Open))
            {
                this.conexion.Close();
            }
        }
    }
}
